package com.gsc.controller;

import com.gsc.domain.ResponseResult;
import com.gsc.domain.dto.AddArticleDto;
import com.gsc.domain.dto.ArticleListDto;
import com.gsc.domain.entity.Article;
import com.gsc.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 文章的接口
 * @author gscstart
 * @create 2023/2/20-14:32
 */
@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 写博文接口
     * @param article
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    /**
     * 分页查询文章列表接口
     * @param articleListDto
     * @return
     */
    @GetMapping("/list")
    public ResponseResult articleList(ArticleListDto articleListDto){
        return articleService.articleLists(articleListDto);
    }

    /**
     * 更新文章回显数据接口
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult selectArticleById(@PathVariable("id") Long id){
        return articleService.selectArticleById(id);
    }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody AddArticleDto addArticleDto, Long id){
        return articleService.updateArticle(addArticleDto, id);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable("id") Long id){
        articleService.removeById(id);
        return ResponseResult.okResult();
    }

}
